package cn.ac.zing.server.hj212.node;

import cn.ac.zing.server.hj212.processor.bean.ProcessorBean;

import java.util.Objects;

/**
 * @Author：dcy
 * @name：NodeContainer
 * @Date：2024/5/19 18:29
 */
public class NodeContainer implements Node {

    public ProcessorBean bean;

    public NodeContainer(ProcessorBean bean) {
        this.bean = bean;
    }

    @Override
    public void execute(Object data) throws Exception {
        preHandle(data);
        processor(data);
        postHandle(data);
    }

    @Override
    public void preHandle(Object data) throws Exception {
        if (Objects.nonNull(bean.getPreProcessor())) {
            bean.getPreProcessor().execute(data);
        }
    }

    @Override
    public void postHandle(Object data) throws Exception {
        if (Objects.nonNull(bean.getPostProcessor())) {
            bean.getPostProcessor().execute(data);
        }
    }

    @Override
    public void processor(Object data) throws Exception {
        if (Objects.nonNull(bean.getProcessor())) {
            bean.getProcessor().execute(data);
        }
    }
}
